package com.itheima.sh.service;

import com.itheima.sh.dao.UserMapper;
import com.itheima.sh.pojo.User;
import com.itheima.sh.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

public class RegisterUserServiceImpl {
    public boolean register(User user) {
        //获取会话对象
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        //获取接口代理对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用查询用户名方法
        User inquire = mapper.inquire(user.getUsername());
        //标记
        boolean f = false;
        //判断用户名是否存在
        if (inquire == null) {
            //存在调用添加方法并将标记改为true
            mapper.register(user);
            f = true;
        }
        //释放资源
        sqlSession.close();
        //返回标记
        return f;
    }
}
